package com.example.demo.Service;

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.example.demo.Entity.Description;
import com.example.demo.Entity.Employee;
import com.example.demo.Entity.Experience;
import com.example.demo.Entity.HumanResource;
import com.example.demo.Entity.Performance;
import com.example.demo.Entity.User;
import com.example.demo.GeneralResponse.APIResponse;
import com.example.demo.Repository.ICompanyRepository;
import com.example.demo.Repository.IDescriptionRepository;
import com.example.demo.Repository.IEmployeeRepository;
import com.example.demo.Repository.IExperienceRepository;
import com.example.demo.Repository.IHRRepository;
import com.example.demo.Repository.IPerformanceRepository;
import com.example.demo.Repository.IUserRepository;
import com.example.demo.utils.DateFormatter;
import com.example.demo.utils.FileUtils;
import com.example.demo.utils.SumofPage;

/**
 * @version: V0.3
 * @author: 郑皓杰 吴嘉鑫
 * @className: HRService
 * @packageName: com.example.demo.Service
 * @description: 这是实现HR业务逻辑的服务类
 * @data: 2021-07-14
 **/

@Service
public class HRService {
	@Autowired
	private IHRRepository hrRepository;
	@Autowired
	private ICompanyRepository companyRepository;
	@Autowired 
	private IEmployeeRepository employeeRepository;
	@Autowired 
	private IExperienceRepository experienceRepository;
	@Autowired
	private IDescriptionRepository descriptionRepository;
	@Autowired
	private IUserRepository userRepository;
	@Autowired
	private IPerformanceRepository perRepository;
	@Autowired
	private MailService mailService;
	
	/**
	* @author:郑皓杰
	* @methodsName: register
	* @description: HR在数据库中进行注册存储
	* @param:  String name,String password,Integer companyId
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> register(String username,String password,Integer companyId) {
		if(!companyRepository.existsById(companyId)) return APIResponse.fail("invalidcompanyid");
		if(hrRepository.findByCompanyID(companyId)!=null) return APIResponse.fail("companyidrepeated");
		User suser = userRepository.findByUsername(username);
		if(suser != null)  return APIResponse.fail("repeatedusername");
		HumanResource hr= new HumanResource();
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		userRepository.save(user);
		hr.setCompanyID(companyId);	 	
		hr.setUsername(username);
		hr.setCompanyName(companyRepository.getById(companyId).getCompanyName());
		hr.setRecruiting(false);
		hrRepository.save(hr);
		return APIResponse.success("successregister",null);
	}
	
	
	
	/**
	* @author:郑皓杰
	* @methodsName: login
	* @description: HR进行登录验证
	* @param:  String name,String password
	* @return: APIResponse
	* @throws: 
	*/
	public String login(String username,String password) {
		HumanResource humanResource = hrRepository.findByUsername(username);
		User user = userRepository.findByUsername(username);
		if(humanResource == null) return "unregisterHR";
		if(!user.getPassword().equals(password)) return "wrongpassword";
		return "successlogin";
	}
	
	/**
	* @author:郑皓杰 吴嘉鑫
	* @methodsName: addEmployeeToCompany
	* @description: HR添加未注册的员工在数据库注册存储
	* @param:  String realname,String gender,String birth,String email,String telephone,String position, String recruited, String salary, Integer companyID, String companyName
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> addEmployeeToCompany(String realname,String gender,String birth,String email,String telephone,String position, String recruited, Integer salary, Integer companyID, String companyName) {
		if(employeeRepository.findBytelephone(telephone)!=null) return APIResponse.fail("telephonerepeated");
		User suser = userRepository.findByUsername(email);
		if(suser != null)  return APIResponse.fail("repeatedemail");
		Employee employee=new Employee();
		User user = new User();
		user.setUsername(email);//默认用户名是email
		user.setPassword(telephone);//默认密码是电话号码
		userRepository.save(user);
		employee.setUsername(email);//默认用户名是email
		employee.setRealname(realname);
		employee.setGender(gender);
		employee.setBirth(DateFormatter.DateTransform(birth));
		employee.setEmail(email);
		employee.setTelephone(telephone);
		employee.setCompanyID(companyID);
		employee.setCompanyName(companyName);
		employee.setFree(false);
		employeeRepository.save(employee);
		Experience experience = new Experience();
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		LocalDate date2 = LocalDate.parse(recruited, fmt);//String转localdate类型
		Description description = new Description();
		description.setEvaluation("无");
		description.setPosition(position);
		description.setRecruited(date2);
		description.setSalary(salary);
		description.setCompanyname(companyName);
		descriptionRepository.save(description);//新建description	
		
		experience.setCompanyID(companyID);
		experience.setEmpid(employee.getEmpid());
		experience.setPosition(position);
		experience.setRecruited(date2);
		experience.setSalary(salary);
		experience.setCompanyname(companyName);
		experience.setDescriptionid(description.getDescriptionid());
		experienceRepository.save(experience);//新建experience
		
		return APIResponse.success("successaddemployee",null);
		
	}
	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: confirm
	* @description: 录用1.输入tel找到员工返回是否存在
	* @param:  String tel
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> confirm(String tel) {
		Employee emp = employeeRepository.findBytelephone(tel);
		if(emp == null) return APIResponse.fail("unregistertelephone");
		if(emp.getCompanyID() != null) return APIResponse.fail("recruitedemployee");
		else return APIResponse.success("existemployee",null);		
	}

	/**
	* @author:吴嘉鑫
	* @methodsName: search
	* @description: 录用2.查找某个员工的个人信息
	* @param:  String tel
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> search(String tel) {
		Employee emp = employeeRepository.findBytelephone(tel);
		emp.setCompanyID(000);
		emp.setEmpid(000);
		return APIResponse.success("successsearch",emp);
	}
	
	/**
	* @author:吴嘉鑫
	* @methodsName: recruit
	* @description: 录用3.确认后,前端依然传入tel，后端找到并修改员工信息，生成新的经历
	* @param:  String tel, Integer companyID , String companyName , String position , String Salary
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> recruit(String tel, Integer companyID , String companyName , String position , Integer Salary) {
		Employee emp = employeeRepository.findBytelephone(tel);
		if(emp.getCompanyName() != null) APIResponse.fail("recruitedemployee");
		emp.setCompanyID(companyID);
		emp.setCompanyName(companyName);//修改员工的所属公司
		emp.setFree(false);
		employeeRepository.save(emp);
		
		Description d = new Description();
		d.setPosition(position);
		d.setRecruited(LocalDate.now());
		d.setSalary(Salary);
		d.setCompanyname(companyName);
		descriptionRepository.save(d);//生成该经历的简易描述	
		
		Experience exp = new Experience();
		Integer empid = emp.getEmpid();//获取经历所属员工ID	
		exp.setEmpid(empid);
		exp.setRecruited(LocalDate.now());
		exp.setCompanyID(companyID);
		exp.setCompanyname(companyName);
		exp.setDescriptionid(d.getDescriptionid());
		exp.setPosition(position);
		exp.setSalary(Salary);
		experienceRepository.save(exp);//生成描述该员工在该公司的经历
		
		return APIResponse.success("successsrecruited",null);
		
	}
	
	
	/**
	* @author:郑皓杰 吴嘉鑫
	* @methodsName: queryEmpByNameOrTel
	* @description: 查看1. Hr在全局通过name和tel查询已注册员工员工
	* @param:  String nameortel,Integer page
	* @return: List<Employee>
	* @throws: 
	*/
	public List<Employee> queryEmpByNameOrTel(String nameortel,Integer page){
		List<Employee> list =new ArrayList<Employee>();
		Employee emp=employeeRepository.findBytelephone(nameortel);
		if(emp!=null) {
			emp.setCompanyID(000000);
			emp.setEmpid(00000000);
			emp.setUsername("user");
			emp.setTelephone(emp.getTelephone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
			list.add(emp);
			return list;
		}
		else {	
	        Sort sort=Sort.by(Sort.Direction.DESC,"empid");
	        Pageable pageable=PageRequest.of(page-1,10,sort);
	        Page<Employee> pages=employeeRepository.findByRealname(nameortel,pageable);
	        List<Employee> list3 = pages.getContent();
			for(Employee temp:list3){
				temp.setCompanyID(000000);
				temp.setEmpid(00000000);
				temp.setUsername("user");
				temp.setTelephone(temp.getTelephone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
				list.add(temp);
				}
			return list;		
		}	
	}
	
	/**
	* @author:吴嘉鑫
	* @methodsName: queryDesBytel
	* @description: 查看2.通过empID查找该员工的所有经历描述，并输出list
	* @param:  String tel
	* @return: APIResponse
	* @throws: 
	*/
	public List<Description> queryDesBytel(String tel){
		List<Description> list = new ArrayList<Description>();
		Employee xiaohong = employeeRepository.findBytelephone(tel);
		Integer empID = xiaohong.getEmpid();
		List<Integer> list1 = experienceRepository.finddesidByempid(empID);
		for(Integer temp:list1) {
			Description des = descriptionRepository.getById(temp);
			list.add(des);
		}
		return list;
	}
	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: queryAuthority
	* @description: 查看3.通过desid查询具体的exp,如果不是该exp所对应公司的HR，则无法查询
	* @param:  Integer companyid, Integer desid
	* @return: String
	* @throws: 
	*/
	public String queryAuthority(Integer companyid, Integer desid) {
		Experience exp = experienceRepository.findByDescriptionid(desid);
		if(companyid != exp.getCompanyID()) return "unauthorizedaccess";
		else return "accessthrough";
	}
	
	/**
	* @author:吴嘉鑫
	* @methodsName: queryExpByexpid
	* @description: 查看4.通过权限后，可以返回exp
	* @param:  Integer desid
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> queryExpByexpid(Integer desid) {
		Experience exp = experienceRepository.findByDescriptionid(desid);
		return APIResponse.success("successquery",exp);
	}
	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: queryOnEmpBycompanyID
	* @description: 管理1.通过companyID查找所有该公司在职员工
	* @param:  Integer  companyID
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> queryOnEmpBycompanyID(Integer  companyID,Integer page){
		List<Integer> list9 = new ArrayList<Integer>();
		List<Experience> list10 = new ArrayList<Experience>();
		List<Experience> list14 = experienceRepository.findByCompanyID(companyID);
		for(Experience temp:list14) {
			if(temp.getSuspended() == null) {
				list10.add(temp);
			}
		}
		for(Experience temp:list10) {
			Integer empid = temp.getEmpid();
			list9.add(empid);
		}   
		Sort sort=Sort.by(Sort.Direction.DESC,"empid");
        Pageable pageable=PageRequest.of(page-1,10,sort);
        Page<Employee> pages=employeeRepository.findByEmpidIn(list9,pageable);
        return APIResponse.success("successquery",pages.getContent());
		//List<Integer> list1 =experienceRepository.findempidBycompanyIDAnd(companyID);//只返回empid,如果出现一人在一个公司工作两次，即用compID查出的多条exp中有相同的empid
        //LinkedHashSet<Integer> hashSet = new LinkedHashSet<>(list1);
        //ArrayList<Integer> list2 = new ArrayList<>(hashSet);//list去重
	}	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: queryOffEmpBycompanyID
	* @description: 管理1.通过companyID查找所有该公司离职员工
	* @param:  Integer  companyID
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> queryOffEmpBycompanyID(Integer companyID,Integer page){ 
		List<Experience> listincompanyall = experienceRepository.findByCompanyID(companyID);
		List<Integer> liststillonwork= new ArrayList<Integer>();
		List<Integer> listalreadyoff=new ArrayList<Integer>();
		for(Experience e:listincompanyall) {
			if(e.getSuspended()!=null) listalreadyoff.add(e.getEmpid());
			else liststillonwork.add(e.getEmpid());
		}
		Map<Integer,Integer> map=new HashMap<>();
		for(int i=0;i<listalreadyoff.size();i++) map.put(listalreadyoff.get(i),i);
		for(int i=0;i<liststillonwork.size();i++) {
			Integer pos=map.get(liststillonwork.get(i));
			if(pos==null) continue;
			listalreadyoff.set(pos,null);
		}
		for(int i=listalreadyoff.size()-1;i>=0;i--)
			if(listalreadyoff.get(i)==null) listalreadyoff.remove(i);
		
		LinkedHashSet<Integer> hashSet = new LinkedHashSet<>(listalreadyoff);
        ArrayList<Integer> list2 = new ArrayList<>(hashSet);//list去重       
		Sort sort=Sort.by(Sort.Direction.DESC,"empid");
        Pageable pageable=PageRequest.of(page-1,10,sort);
        Page<Employee> pages=employeeRepository.findByEmpidIn(list2,pageable);
        return APIResponse.success("successquery",pages.getContent());
	}
	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: queryexp
	* @description: 管理2. 查看某位员工的经历
	* @param:  String tel , Integer companyID
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> queryexp(String tel , Integer companyID) {
		Integer empid = employeeRepository.findempidBytel(tel);
		Experience exp = experienceRepository.findByEmpidAndCompanyID(empid, companyID);
		return APIResponse.success("successquery",exp);
	}
	
	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: setPosition
	* @description: 管理3.修改员工职位
	* @param:  String tel, Integer comapnyID, String position
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> setPosition(String tel, Integer comapnyID, String position) {
		Employee emp = employeeRepository.findBytelephone(tel);
		Integer empid = emp.getEmpid();
		Experience exp = experienceRepository.findByEmpidAndCompanyID(empid, comapnyID);
		exp.setPosition(position);
		experienceRepository.save(exp);
		return APIResponse.success("successset",null);
	}
	
	/**
	* @author:吴嘉鑫
	* @methodsName: setSalary
	* @description: 管理4.修改员工薪资
	* @param:  String tel, Integer comapnyID, String salary
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> setSalary(String tel, Integer comapnyID, Integer salary) {
		Employee emp = employeeRepository.findBytelephone(tel);
		Integer empid = emp.getEmpid();
		Experience exp = experienceRepository.findByEmpidAndCompanyID(empid, comapnyID);
		exp.setSalary(salary);
		experienceRepository.save(exp);
		return APIResponse.success("successset",null);
	}
	
	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: suspend
	* @description: 员工离职
	* @param:  String tel, Integer comapnyID
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> suspend(String tel, Integer companyID,String evaluation) {
		Employee emp = employeeRepository.findBytelephone(tel);
		Integer empid = emp.getEmpid();
		Experience exp = experienceRepository.findByEmpidAndCompanyID(empid, companyID);
		exp.setSuspended(LocalDate.now());
		experienceRepository.save(exp);//为这次经历设置离职时间
		evaluate(tel,companyID,evaluation);
		emp.setCompanyID(null);
		emp.setCompanyName(null);
		emp.setFree(true);
		employeeRepository.save(emp);//将员工档案中公司信息清除
		return APIResponse.success("successsuspend",null);
	}
	
	/**
	* @author:郑皓杰
	* @methodsName: searchFree
	* @description: 查询自由人员工
	* @param:  
	* @return:List<Employee>
	* @throws: 
	*/
	public List<Employee> searchFree(){
		return employeeRepository.findByState(true);
	}
	
	/**
	* @author:吴嘉鑫 郑皓杰
	* @methodsName: upload
	* @description: 上传文件
	* @param:  MultipartFile file
	* @return: APIResponse
	* @throws: IOException
	*/
	
	public String upload(MultipartFile file,String key) throws IOException{
		return FileUtils.upload(file,key);
	}
	
	
	
	
	/**
	* @author:吴嘉鑫 郑皓杰
	* @methodsName: download
	* @description: 读取文件
	* @param:  MultipartFile file
	* @return: APIResponse
	* @throws: IOException
	*/
	public APIResponse<?> download(String key,HttpServletResponse response) throws IOException{
		FileUtils.download(key,response);
		return APIResponse.success("下载成功",null);
	}
	
	/**
	* @author:郑皓杰 吴嘉鑫
	* @methodsName: pagessum
	* @description: hr查看时返回总页面
	* @param:  String nameortel
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> pagessum(String nameortel){
		List<Employee> list =new ArrayList<Employee>();
		Employee emp=employeeRepository.findBytelephone(nameortel);
		if(emp!=null) {
			list.add(emp);
		}
		else {	
	        List<Employee> list2=employeeRepository.findByRealname(nameortel);
			for(Employee temp:list2){;
				list.add(temp);
				}		
		}
		Integer sum = SumofPage.getSumofPages(list);
		return APIResponse.success("successquery",sum);	
	}
	
	/**
	* @author:郑皓杰 吴嘉鑫
	* @methodsName: pageOnsum
	* @description: hr管理时返回在职总页数
	* @param:  Integer companyID
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> pageOnsum(Integer companyID){
		System.out.println(companyID);
		List<Integer> list11 = experienceRepository.findEmpidBycompanyIDAndStillOnWork(companyID);
		//List<Experience> list1 = experienceRepository.findBycompanyIDAndStillOnWork(companyID);
		System.out.println(list11);
		//List<Integer> list1 =experienceRepository.findempidBycompanyID(companyID);//只返回empid,如果出现一人在一个公司工作两次，即用compID查出的多条exp中有相同的empid
        //LinkedHashSet<Integer> hashSet = new LinkedHashSet<>(list1);
        //ArrayList<Integer> list2 = new ArrayList<>(hashSet);//list去重
        Integer Onsum = SumofPage.getSumofPage(list11);
		//Integer sum = SumofPage.getSumofPage(list2);
		return APIResponse.success("successquery",Onsum);	
	}
	
	/**
	* @author:郑皓杰 吴嘉鑫
	* @methodsName: pageOffsum
	* @description: hr管理时返回在职总页数
	* @param:  Integer companyID
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> pageOffsum(Integer companyID){
		List<Integer> list11 = experienceRepository.findEmpidBycompanyIDAndStillOnWork(companyID);
		List<Integer> list1 =experienceRepository.findempidBycompanyID(companyID);//只返回empid,如果出现一人在一个公司工作两次，即用compID查出的多条exp中有相同的empid
        LinkedHashSet<Integer> hashSet = new LinkedHashSet<>(list1);
        ArrayList<Integer> list2 = new ArrayList<>(hashSet);//list去重
        Integer Onsum = SumofPage.getSumofPage(list11);
		Integer sum = SumofPage.getSumofPage(list2);
		return APIResponse.success("successquery",sum-Onsum==0?1:sum-Onsum);	
	}
	
	/**
	* @author:郑皓杰 吴嘉鑫
	* @methodsName: queryOurEmpBynameortel
	* @description: hr管理时查询某些员工
	* @param:  String nameortel
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> queryOurEmpBynameortel(Integer companyID,String nameortel){
		List<Employee> list = new ArrayList<Employee>();
		List<Integer> list1 =experienceRepository.findempidBycompanyID(companyID);//只返回empid,如果出现一人在一个公司工作两次，即用compID查出的多条exp中有相同的empid
        LinkedHashSet<Integer> hashSet = new LinkedHashSet<>(list1);
        ArrayList<Integer> list2 = new ArrayList<>(hashSet);
        List<Employee> list3=employeeRepository.findByEmpidIn(list2);
        for(Employee temp:list3) {
        	if(temp.getTelephone().equals(nameortel)) {
        		list.add(temp);
        		return APIResponse.success("successquery",list);
        	}
        	else if(temp.getRealname().equals(nameortel)){
        		list.add(temp);
        	}
        }
        if(list.size() == 0)return APIResponse.fail("查无此人");  	 
       	return APIResponse.success("successquery",list);
}
	
	/**
	* @author:吴嘉鑫
	* @methodsName: evaluate
	* @description: 修改评价
	* @param:  String tel, Integer comapnyID, String evaluation
	* @return: 
	* @throws: 
	*/
	public void evaluate(String tel, Integer comapnyID, String evaluation) {
		Employee emp = employeeRepository.findBytelephone(tel);
		Integer empid = emp.getEmpid();
		Experience exp = experienceRepository.findByEmpidAndCompanyID(empid, comapnyID);
		Integer desid = exp.getDescriptionid();
		Description des = descriptionRepository.findByDescriptionid(desid);
		des.setEvaluation(evaluation);
		descriptionRepository.save(des);
	}
	
	/**
	* @author:郑皓杰
	* @methodsName: writePerformance
	* @description: 为员工写绩效
	* @param:  Integer empid,Integer rank,String text
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> writePerformance(Integer expid,Integer rank,String title,String text,Date start,Date end){
		Performance p=new Performance();
		p.setExpid(expid);
		p.setRank(rank);
		p.setTitle(title);
		p.setText(text);
		p.setStart(start);
		p.setEnd(end);
		perRepository.save(p);
		return APIResponse.success("success writedown",null);
	}
	/**
	* @author:郑皓杰
	* @methodsName: writePerformance
	* @description: 获取已写员工绩效
	* @param:  Integer empid,Integer rank,String text
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> getPerformance(Integer expid){
		return APIResponse.success("successquery",perRepository.findByExpid(expid));
	}
	
	/**
	* @author:郑皓杰
	* @methodsName: writePerformance
	* @description: 修改已写员工绩效
	* @param:  Integer empid,Integer rank,String text
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> modifyPerformance(Integer perid,String title,String newtext){
		Performance p=perRepository.findByPerid(perid);
		p.setTitle(title);
		p.setText(newtext);
		perRepository.save(p);
		return APIResponse.success("success modifying",null);
	}
	
	/**
	* @author:郑皓杰
	* @methodsName: deletePerformance
	* @description: 删除已写员工绩效
	* @param:  Integer perid
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> deletePerformance(Integer perid){
		perRepository.delete(perRepository.findByPerid(perid));
		return APIResponse.success("success deleting",null);
	}
	/**
	* @author:郑皓杰
	* @methodsName: searchByJobKey
	* @description: 根据职位关键词模糊查询
	* @param:  String jobname,Integer page
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> searchByJobKey(String jobname,Integer page){
		List<Employee> list = new ArrayList<Employee>();
		List<Experience> list1=experienceRepository.findByJobKeyword(jobname);
		List<Integer> list2=new ArrayList<Integer>();
		for(Experience e:list1) {
			list2.add(e.getEmpid());
		} 
		ArrayList<Integer> list3 = new ArrayList<>(new LinkedHashSet<Integer>(list2));
		Sort sort=Sort.by(Sort.Direction.DESC,"empid");
        Pageable pageable=PageRequest.of(page-1,10,sort);
        Page<Employee> pages=employeeRepository.findByEmpidIn(list3,pageable);
        List<Employee> list114514 = pages.getContent();
        for(Employee temp:list114514) {
        	temp.setCompanyID(0);
        	temp.setUsername("username");
        	temp.setEmpid(0);
        	list.add(temp);
        }
        return APIResponse.success("successquery",list);
	}	
	
	
	
	
	/**
	* @author:吴嘉鑫
	* @methodsName: sendEmail
	* @description: hr先心仪的员工发送面试邮件
	* @param:  Integer empid,Integer rank,String text
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> sendEmail(String email,String text,String subject) throws Throwable{
		mailService.sendTextMail(email, subject, text);
		return APIResponse.success("sendsuccess",null);
	}

	/**
	* @author:吴嘉鑫
	* @methodsName: wasterate
	* @description: hr考察公司的流失率
	* @param:  Integer empid,Integer rank,String text
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> wasterate(String email,String text,String subject) throws Throwable{
		mailService.sendTextMail(email, subject, text);
		return APIResponse.success("sendsuccess",null);
	}
	
	
	
	
	
	
	
}
